package huawei;

public class Test_0522 {
    public static void main(String[] args) {
        int[][] arr = {{1,4,7,11,15}, {2,5,8,12,19},{3,6,9,16,22}, {10,13,14,17,24}, {18,21,23,26,30}};
        System.out.println(matrixSort(arr, 16));
    }

    private static boolean matrixSort(int[][] arr, int target) {
        // 遍历行
        for (int i = 0; i < arr.length; i++) {
            int[] ax = arr[i];
            for (int j = 0; j < ax.length; j++) {
                // 如果刚刚等于则返回
                if (arr[i][j] == target) {
                    return true;
                }
                // 行是有序的，如果目标值小于行未元素就调到下一行
                if (arr[i][ax.length - 1] < target) {
                    break;
                }
            }
        }
        return false;
    }
}
